# coding: utf-8
import logging
import threading
import datetime
from core.JZ_part2 import JZThread


class QJZ(threading.Thread):
    """
        循环执行报名讲座操作
    """
    def __init__(self,usernames,passwords):
        threading.Thread.__init__(self)
        self.usernames = usernames #学号列表
        self.passwords = passwords #密码列表



    def run(self):
        self.startQJZ()

    def startQJZ(self):
        logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        logger = logging.getLogger(__name__)
        num = 0
        logger.info('开始抢讲座')
        while True:
            hour = datetime.datetime.now().hour
            min = datetime.datetime.now().min
            if '06' <= str(hour) < '23' or (str(hour) == '23' and str(min) <= '55'):
                #在6点到23点55分之间抢讲座。在0-6点之间无法通过外网进入学校官网
                for username,password in zip(self.usernames,self.passwords):
                    thread = JZThread(username, password)
                    thread.start()
                    thread.join()
                num += 1
                logger.info('第{}轮已完成'.format(num))




